package org.jeecg.modules.meta.service.impl;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.metasyn.entity.FdColumn;
import org.jeecg.metasyn.entity.FdTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("metaSynDBOperTimeServiceImpl")
public class MetaSynDBOperTimeServiceImpl extends AbstractMetaSynDBOperService  {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    List<FdTable> synMetaTablePage(long current, long size, Date date) {
        IPage<FdTable> page = new Page(current, size);
        QueryWrapper<FdTable> queryWrapper = new QueryWrapper();
        queryWrapper.between("fd_updatetime", DateUtil.formatDate(date) + " 00:00:00", DateUtil.formatDate(date) + " 23:59:59");
        //获取元数据平台表数据
        IPage<FdTable> tableList = fdTableMapper.selectPage(page, queryWrapper);
        if (null == tableList || tableList.getRecords().size() == 0) {
            return new ArrayList<>();
        }

        return tableList.getRecords();
    }

    @Override
    List<FdColumn> synMetaFieldPage(long current, long size, Date date) {
        IPage<FdColumn> page = new Page(current, size);
        QueryWrapper<FdColumn> queryWrapper = new QueryWrapper();
        queryWrapper.between("fd_updatetime", DateUtil.formatDate(date) + " 00:00:00", DateUtil.formatDate(date) + " 23:59:59");
        //获取元数据平台表数据
        IPage<FdColumn> tableList = fdColumnMapper.selectPage(page, queryWrapper);
        if (null == tableList || tableList.getRecords().size() == 0) {
            return new ArrayList<>();
        }

        return tableList.getRecords();
    }

    @Override
    void printLog(Date date) {
        log.info("执行元数据同步当日操作!日期=" + DateUtil.formatDateTime(date));
    }

    /**日同步不做删除操作*/
    @Override
    void updateStatusByTime(Date date) {
    }

    @Override
    void updateFieldStatusByTime(Date date) {
    }
}
